#ifndef CRYPTO_COMMON_H
#define CRYPTO_COMMON_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <stdint.h>

// 安全配置常量
#define KEY_LENGTH 1024          // 增加密钥长度
#define SALT_LENGTH 64           // 盐值长度
#define BLOCK_SIZE 16            // 分块大小
#define ROUNDS 8                 // 加密轮数
#define BUFFER_SIZE 16384        // 缓冲区大小16KB

// 密钥结构体
typedef struct {
    unsigned char primary_key[KEY_LENGTH];
    unsigned char salt[SALT_LENGTH];
    unsigned char derived_keys[ROUNDS][KEY_LENGTH];
    uint32_t seed;
    uint8_t complexity_level;
} crypto_context_t;

// 函数声明
void secure_random_init(void);
void generate_secure_random(unsigned char *buffer, size_t length);
void derive_keys(crypto_context_t *ctx);
void hash_function(const unsigned char *input, size_t len, unsigned char *output);
void xor_block(unsigned char *data, const unsigned char *key, size_t length);
void rotate_left(unsigned char *data, size_t length, int positions);
void rotate_right(unsigned char *data, size_t length, int positions);
void substitute_bytes(unsigned char *data, size_t length, const unsigned char *sbox);
void inverse_substitute_bytes(unsigned char *data, size_t length, const unsigned char *inv_sbox);

// 加密解密核心函数
void advanced_encrypt_block(unsigned char *block, size_t block_size, crypto_context_t *ctx);
void advanced_decrypt_block(unsigned char *block, size_t block_size, crypto_context_t *ctx);

// S-Box 和逆S-Box
extern const unsigned char SBOX[256];
extern const unsigned char INV_SBOX[256];

#endif // CRYPTO_COMMON_H